package com.ln.dm1108.demo01;

/**
 * @author Ln
 * @version 终极版
 * @date 2022/11/8 15:48
 */
public class Test02 {
    public static void main(String[] args) {
        Pig pig = new Pig();
        pig.start();

        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("主线程设置t线程的参数来止损失");
        pig.setFlag(false);
    }
}
class Pig extends Thread{
    private volatile boolean flag=true;

    public void setFlag(boolean flag) {
        this.flag = flag;
    }

    @Override
    public void run() {
        System.out.println("run方法");
        while (flag){

        }
    }
}
